//
//  WGMainViewController.m
//  DanTang
//
//  Created by taolei on 17/3/15.
//  Copyright © 2017年 taolei. All rights reserved.
//

#import "WGMainViewController.h"
#import "WGNavigationViewController.h"
#import "WGHomeViewController.h"
#import "WGItemViewController.h"
#import "WGCategotyViewController.h"
#import "WGPersonViewController.h"
#import "UIImage+Extension.h"


@interface WGMainViewController ()

@end

@implementation WGMainViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self addAllChildVC];
}

+ (void)initialize
{
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:11];
    attrs[NSForegroundColorAttributeName] = [UIColor grayColor];
    
    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
    selectedAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:11];
    selectedAttrs[NSForegroundColorAttributeName] = [UIColor colorWithRed:245/255.0 green:80/255.0 blue:83/255.0 alpha:1.0];
    
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:attrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
}

- (void)addAllChildVC
{
    [self addOneChildVC:[[WGNavigationViewController alloc] initWithRootViewController:[[WGHomeViewController alloc] init]] title:@"首页" imageName:@"TabBar_home_23x23_" selectedImageName:@"TabBar_home_selected_23x23_"];
    
     [self addOneChildVC:[[WGNavigationViewController alloc] initWithRootViewController:[[WGItemViewController alloc] init]] title:@"单品" imageName:@"TabBar_gift_23x23_" selectedImageName:@"TabBar_gift_selected_23x23_"];
    
     [self addOneChildVC:[[WGNavigationViewController alloc] initWithRootViewController:[[WGCategotyViewController alloc] init]] title:@"分类" imageName:@"TabBar_category_23x23_" selectedImageName:@"TabBar_category_Selected_23x23_"];
    
     [self addOneChildVC:[[WGNavigationViewController alloc] initWithRootViewController:[[WGPersonViewController alloc] init]] title:@"个人" imageName:@"TabBar_me_boy_23x23_" selectedImageName:@"TabBar_me_boy_selected_23x23_"];
}

/**
 *  添加一个子控制器(UINavigationController)

 @param childVC 子控制器
 @param title 标题
 @param imageName 图标
 @param selectedImageName 选中图标
 */
- (void)addOneChildVC:(UIViewController *)childVC title:(NSString *)title imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName
{
    childVC.tabBarItem.title = title;
    childVC.tabBarItem.image = [UIImage wg_imageOriginalWithName:imageName];
    childVC.tabBarItem.selectedImage = [UIImage wg_imageOriginalWithName:selectedImageName];
    [self addChildViewController:childVC];
}

@end
